package com.zz.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Locale;
import java.util.Objects;

/**
 * 支持协议类型
 *
 * @author zz
 */
@Getter
@AllArgsConstructor
public enum ProxyType {

    TCP(0, "tcp"),
    HTTP(1, "http"),
    HTTPS(2, "https");

    private final int code;
    private final String desc;

    public static ProxyType getInstance(int code) {
        for (ProxyType value : ProxyType.values()) {
            if (value.code == code) {
                return value;
            }
        }
        return null;
    }

    public static ProxyType getInstance(String desc) {
        for (ProxyType value : ProxyType.values()) {
            if (Objects.equals(value.desc, desc.toLowerCase(Locale.ROOT))) {
                return value;
            }
        }
        return null;
    }

}
